package com.hzw.service.impl;

import com.hzw.bean.User;
import com.hzw.dto.UserInfo;
import com.hzw.dao.UserMapper;
import com.hzw.service.UserService;
import com.hzw.utils.TokenUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/2/26.
 */
@Service
public class UserServiceImpl implements UserService{
    @Resource
    private UserMapper userMapper;

    @Override
    public int checkExistUserName(String userName) {
        return userMapper.checkExistUserName(userName);
    }

    @Override
    public int checkPassword(User user) {
        return userMapper.checkPassword(user);
    }

    @Override
    public UserInfo getUserInfo(User user) {
        String id = user.getId();
        String userName = user.getUserName();
        String token = TokenUtils.createTokenByUserId(id);  //利用userId生成一个token返回给客户端浏览器
        UserInfo userInfo = new UserInfo(id,userName,token);    //创建一个包含userId和token的实体
        return userInfo;
    }

    @Override
    public int updateUserById(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int updatePassword(User user) {
        return userMapper.updatePassword(user);
    }

    @Override
    public User selectUserById(String userId) {
        return userMapper.selectUserById(userId);
    }

    @Override
    public List<User> selectUserByKeyWord(String keyWord) {
        return userMapper.selectUserByKeyWord(keyWord);
    }

    @Override
    public List<User> selectFocusUserById(String userId) {
        return userMapper.selectFocusUserById(userId);
    }

    @Override
    public List<User> selectFollowUserById(String userId) {
        return userMapper.selectFollowUserById(userId);
    }
}
